package com.wn.controller;

import com.common.entity.Rsp;
import com.common.entity.UserCoupon;
import com.wn.service.UserCouponService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UserCouponController {
    @Autowired
    private UserCouponService userCouponService;



    /**
     * @ClassName
     * @Description :根据用户id查询优惠券列表
     * @param : id
     * @Return :
     * @Author : 汪雄
     * @Date :
     */
    @GetMapping("searchUserCouponList/{userid}")
    public Rsp searchUserCouponList(@PathVariable("userid") String id,
                                   @RequestHeader("token")String token){
        Rsp rsp = userCouponService.searchList(id);
        return rsp;
    }

    /**
     * @ClassName
     * @Description :根据id查询详情
     * @param : id
     * @Return :
     * @Author : 汪雄
     * @Date :
     */
    @GetMapping("getOneByIdUserCoupon/{id}")
    @ApiOperation("根据id查询")
    public Rsp getOneByIdUserCoupon(@PathVariable("id") String id,
                                   @RequestHeader("token")String token){
       UserCoupon oneById = userCouponService.getOneById(id);
        return Rsp.success(oneById);
    }


    @PostMapping("updateUserCoupon")
    @ApiOperation("修改用户优惠券详情")
    public Rsp updateUserCoupon(@RequestBody UserCoupon userCoupon,
                               @RequestHeader("token") String token){
        return userCouponService.update(userCoupon);
    }

    @PutMapping("addOneUserCoupon")
    @ApiOperation("添加优惠券")
    public Rsp addOneUserCoupon(@RequestBody UserCoupon userCoupon,
                                @RequestHeader("token")String token){
        Rsp rsp = userCouponService.addOne(userCoupon);
        return rsp;
    }

    /**
     * @ClassName
     * @Description : deleteLogical删除计划
     * @param :
     * @Return :
     * @Author : 汪雄
     * @Date :
     */
    @DeleteMapping("deleteTrueUserCoupon/{id}")
    @ApiOperation("物理删除用户优惠券详情项")
    public Rsp deleteTrueUserCoupon(@PathVariable("id") String id,
                                   @RequestHeader("token") String token){
        return userCouponService.deleteOneTrue(id);
    }


}
